<template>
  <div class="adoptedRefundList">
    <search-block type="flex">
      <el-form inline :model="model" @submit.native.prevent>
        <el-form-item label="物品编号:">
          <el-input v-model="model.adoptedSn" clearable></el-input>
        </el-form-item>
        <!--      <el-form-item label="名称:">
                <el-input v-model="model.adoptedName" clearable></el-input>
              </el-form-item>-->
      </el-form>
      <template slot="button">
        <el-button type="primary" @click="search(true)">查询</el-button>
      </template>
    </search-block>
    <y-table
      ref="table"
      border
      pagination
      :getDataWay="getDataWay"
      :columns="columns">
      <el-table-column slot="status" label="阶段" align="center" header-align="center" width="150">>
        <template v-slot="{row}">
          <span :class="statusClass(row)">{{$$getCommonArrayName(row.status, adoptedRefundStatusOptions)}}</span>
        </template>
      </el-table-column>
      <el-table-column slot="y-oper" label="操作" align="center" header-align="center" width="80">
        <template v-slot="{row}">
          <div class="table-buttons">
            <el-button size="mini" @click="showDetails(row)">查看</el-button>
          </div>
        </template>
      </el-table-column>
    </y-table>
    <el-drawer
      :visible.sync="viewForms.showForm"
      title="退单详情"
      :size="1000"
      destroy-on-close>
      <adopted-refund-info
        v-if="viewForms.currentForm && viewForms.currentForm.id"
        :id="viewForms.currentForm.id"
        :adopted-id="viewForms.currentForm.adoptedId"
        @close-drawer="viewForms.showForm = false"
        @refresh="search"></adopted-refund-info>
    </el-drawer>
  </div>
</template>

<script>
import adoptedRefundInfo from "./adoptedRefundDetails/adoptedRefundInfo";
export default {
  name: "adoptedRefundList",
  components: { adoptedRefundInfo },
  inject: ['getEnum'],
  computed:{
    getDataWay(){
      return {
        dataType: 'url',
        data: this.$api.adopted.adoptedReturnPage,
        param: this.model
      }
    },
  },
  data(){
    return{
      adoptedRefundStatusOptions: this.getEnum('adoptedRefundStatus'),
      model:{
        adoptedSn: ''
      },
      columns: [
        {
          label: "物品编号",
          prop: "adoptedSn",
          minWidth: 90
        },
        {
          label: "退货方",
          prop: "memberName",
          minWidth: 120
        },
        {
          label: "申请时间",
          prop: "commitTime",
          minWidth: 170,
          formatter({commitTime}){
            return commitTime.replace('T', ' ');
          }
        },
        {
          label: "支付方式",
          prop: "payType",
          minWidth: 100,
          formatter: (function(row){
            return this.$$getCommonArrayName(row.payType, Object.values(this.getEnum('commonPayType'))) || '无'
          }).bind(this)
        },
        {
          label: "支付金额(元)",
          prop: "realPrice",
          minWidth: 100
        },
        {
          prop: "status",
          template: true
        }
      ],
      viewForms:{
        currentForm: {},
        showForm: false,
      }
    }
  },
  methods:{
    search(jumpToFirst){
      this.$refs['table'].loadData(this.model, jumpToFirst);
    },
    showDetails(row){
      this.$set(this.viewForms, 'currentForm', row);
      this.viewForms.showForm = true;
    },
    statusClass({status}){
      switch(status){
        case '0': return 'y-warning';
        case '1':case '4': return 'y-primary';
        case '2': return 'y-success';
        case '3': return 'y-info';
      }
      return '';
    }
  }
}
</script>

<style scoped>

</style>